package com.hphs.controller;


import com.hphs.model.Product;
import com.hphs.service.ProductService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Controller  表示当前是控制层 并把当前类交给springBoot容器来处理
 * @ResponseBody 返回给前端的字符 json字符
 * */
@RestController
@RequestMapping("api/product")
@CrossOrigin //解决跨域访问问题
public class ProductController {
    @Autowired
    private ProductService service;

    @GetMapping
    public List<Product> findAll(){
        List<Product> all = service.findAll();
        return all;
    }

}
